<template>
  <div>
    <div class="tab" v-if="!nodata && !reasult.length">
      <div class="tab-down">
        <div
          v-for="(item,index) in arrGame"
          :key="index"
          class="cp"
          :class="index === tabT2?'tab-d-select':'dhover'"
          @click="tabTap(index,'tabT2')"
        >
          <a :href="'#listid'+index">{{item.type}}</a>
        </div>
      </div>
    </div>

    <div v-if="reasult.length>0">
      <a-row type="flex" class="list">
        <a-col :span="8" v-for="(itemL,indexL) in reasult" :key="indexL" class="list-item cp">
          <a-col :span="12" class="list-item-l" @click="onJump(itemL)">
            <img :src="itemL.icon" alt srcset />
          </a-col>
          <a-col :span="12" class="list-item-r">
            <a-row>
              <a-col :span="14" @click="onJump(itemL)">{{itemL.name}}</a-col>
              <a-col :span="10">{{itemL.index}}件</a-col>
            </a-row>
            <a-row type="flex" class="list-item-r-b">
              <div
                v-for="(itemc,indexc) in itemL.cate"
                :key="indexc"
                @click="onJump(itemL,itemc)"
              >{{itemc.name}}</div>
            </a-row>
          </a-col>
        </a-col>
      </a-row>
    </div>

    <div v-if="nodata">
      <a-row type="flex" class="list">
        <a-col :span="8" class="list-item cp">
          <div>暂无数据！</div>
        </a-col>
      </a-row>
    </div>
    <div v-if="!nodata && !reasult.length">
      <div v-for="(item,index) in arrGame" :key="index">
        <a-row type="flex" class="list" :id="'listid' + index" v-if="item.list.length>0">
          <div class="labels">{{item.type}}</div>
          <a-col :span="8" v-for="(itemL,indexL) in item.list" :key="indexL" class="list-item cp">
            <a-col :span="12" class="list-item-l" @click="onJump(itemL)">
              <img :src="itemL.icon" alt srcset />
            </a-col>
            <a-col :span="12" class="list-item-r">
              <a-row>
                <a-col :span="14" @click="onJump(itemL)">{{itemL.name}}</a-col>
                <a-col :span="10">{{itemL.count}}件</a-col>
              </a-row>
              <a-row type="flex" class="list-item-r-b">
                <div
                  v-for="(itemc,indexc) in itemL.cate"
                  :key="indexc"
                  @click="onJump(itemL,itemc)"
                >{{itemc.name}}</div>
              </a-row>
            </a-col>
          </a-col>
        </a-row>
      </div>
    </div>

  </div>
</template>

<script>
import { GAT_LIST } from "./server";
export default {
  layout: "main",
  asyncData(context) {
    return {
      contents: "游戏",
      arrGame: [
        { type: "热门", list: [] },
        { type: "A", list: [] },
        { type: "B", list: [] },
        { type: "C", list: [] },
        { type: "D", list: [] },
        { type: "E", list: [] },
        { type: "F", list: [] },
        { type: "G", list: [] },
        { type: "H", list: [] },
        { type: "I", list: [] },
        { type: "J", list: [] },
        { type: "K", list: [] },
        { type: "L", list: [] },
        { type: "M", list: [] },
        { type: "N", list: [] },
        { type: "O", list: [] },
        { type: "P", list: [] },
        { type: "Q", list: [] },
        { type: "R", list: [] },
        { type: "S", list: [] },
        { type: "T", list: [] },
        { type: "U", list: [] },
        { type: "V", list: [] },
        { type: "W", list: [] },
        { type: "X", list: [] },
        { type: "Y", list: [] },
        { type: "Z", list: [] }
      ],
      reasult: [],
      nodata: false
    };
  },
  data() {
    return {
      tabT1: 0,
      tabT2: -1
    };
  },
  created() {
    if (this.$route.params.search) {
      GAT_LIST({
        search: this.$route.params.search
      }).then(res => {
        if (res == null) {
          this.reasult = []
          this.nodata = true
        } else {
          this.reasult = res.data
          // this.nodata = false
        }
      });
    }
    this.getList()
  },
  methods: {
    onJump(item, cate) {
      this.$router.push({
        name: "game-list",
        params: {
          list: item.list_id,
          cate_id: cate ? cate.cate_id : "",
          cate_name: cate ? cate.name : "",
          type: "game"
        }
      });
    },
    tabTap(i, t) {
      this[t] = i;
    },
    getList() {
      GAT_LIST().then(res => {
        if (!res) return;
        this.arrGame[0].list = res.data.hot;
        res.data.list.forEach(ele => {
          this.arrGame.forEach(eles => {
            if (ele.chart === eles.type) {
              eles.list.push(ele);
            }
          });
        });
      });
    }
  },
  watch: {
    "$store.state.search"(v) {
      GAT_LIST({
        search: v
      }).then(res => {
        if (res == null) {
          this.reasult = []
          this.nodata = true
        } else {
          this.reasult = res.data
          this.nodata = false
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
.tab {
  width: 100%;
  border: 1px solid #f6f6f6;
  margin-bottom: 10px;
  position: sticky;
  top: 0;
  z-index: 99;
  background: #0084ff;
  .tab-top {
    height: 40px;
    line-height: 40px;
    text-align: center;
    background: #f6f6f6;
    .tab-t-select {
      background: #fff;
    }
  }
  .tab-down {
    min-height: 56px;
    display: flex;
    flex-wrap: wrap;
    font-size: 18px;
    padding: 6px 0 0 12px;
    div {
      width: 28px;
      height: 28px;
      line-height: 28px;
      text-align: center;
      margin: 6px 6px;
      font-weight: 500;
      &:nth-child(1) {
        width: 60px;
      }
      a {
        display: inline-block;
        width: 100%;
        height: 100%;
        color: #333;
      }
    }
    .dhover {
      a {
        color: #fff;
      }
    }
    .dhover:hover {
      background: rgba(255,235,59,0.85);
    }
    .tab-d-select {
      background: rgba(255,235,59,0.85);
      // border: 1px solid #f6f6f6;
      a {
        color: #fff;
      }
    }
  }
}
.list {
  border: 1px solid #f6f6f6;
  padding-top: 14px;
  margin-bottom: 10px;
  position: relative;
  .labels {
    position: absolute;
    top: 0;
    left: 0;
    width: 26px;
    min-height: 28px;
    text-align: center;
    writing-mode: lr-tb;
    background: #f6a12c;
    color: #fff;
    padding: 4px;
    &::after {
      content: "";
      display: block;
      position: absolute;
      left: 0;
      bottom: -12px;
      width: 0;
      height: 0;
      border-width: 6px 12px;
      border-color: #f6a12c transparent transparent #f6a12c;
      border-style: solid;
    }
  }
  .list-item {
    padding-left: 46px;
    margin-bottom: 24px;
    .list-item-l {
      width: 94px;
      height: 94px;
      border-radius: 5px;
      border: 1px solid #f6f6f6;
      overflow: hidden;
      img {
        width: 94px;
        height: 94px;
      }
    }
    .list-item-r {
      padding-left: 10px;
      .list-item-r-b {
        margin-top: 4px;
        div {
          height: 30px;
          line-height: 30px;
          padding: 0 6px;
          background: #dfe5e9;
          color: #6c8db7;
          margin: 0 4px 4px 0;
          border-radius: 5px;
        }
      }
    }
  }
}
</style>